<!-- 角色编辑弹窗 -->
<template>
  <div class="drawerDetail">
    <el-drawer :visible="drawerEditBoolen"
               size="50%"
               :before-close="handleClose"
               ref="drawer"
               :with-header="false">
      <!-- 订单信息 -->

      <el-card shadow="never">
        <!-- 搜索表单 -->
        <!-- <role-search @search="reload" /> -->
        <!-- 数据表格 -->

        <ele-pro-table ref="table"
                       :columns="columns"
                       :datasource="datasource"
                       tool-class="ele-toolbar-form"
                       row-key="id">
          <!-- 表头工具栏 -->
          <template v-slot:toolbar>

          </template>

          <template v-slot:img="{ row }">
            <div><img class="categoryImages"
                   :src="row.img"
                   alt="" /></div>
          </template>

          <template v-slot:content="{ row }">
            <div v-html="row.content"></div>
          </template>

          <!-- 状态列 -->
          <template v-slot:sex="{ row }">
            {{ row.sex==0?'性别不限':row.sex==1?'男':'女' }}
          </template>
          <template v-slot:level="{ row }">
            <div>
              {{ row.level==0?'普通用户':'vip用户' }}
            </div>
          </template>
          <template v-slot:name="{ row }">
            <div v-if="row.name">
              <div class="realNameStyle">
                <img class="avaterName"
                     :src="row.img"
                     alt="" />
                <span>{{ row.name }}</span>
              </div>
            </div>
            <div v-else>-----</div>
          </template>
          <template v-slot:nickname="{ row }">
            <div v-if="row.nickname">
              <div class="realNameStyle">
                <img class="avaterName"
                     :src="row.avatar"
                     alt="" />
                <span>{{ row.nickname }}</span>
              </div>
            </div>
            <div v-else>-----</div>
          </template>
          <template v-slot:join_nickname="{ row }">
            <div v-if="row.join_nickname">
              <div class="realNameStyle">
                <img class="avaterName"
                     :src="row.join_avatar"
                     alt="" />
                <span>{{ row.join_nickname }}</span>
              </div>
            </div>
            <div v-else>-----</div>
          </template>
          <!-- <template v-slot:sort="{ row }">
          <i class="sort-handle el-icon-rank ele-text-secondary"
             style="cursor: move"></i>
          <div v-if="false">{{ row }}</div>
        </template> -->
          <!-- 操作列 -->

        </ele-pro-table>
      </el-card>

    </el-drawer>
    <!-- 图片预览 -->
    <el-image-viewer v-if="viewerVisible"
                     style="z-index: 9999"
                     :on-close="closeViewer"
                     :url-list="imgViewArr" />
    <el-button type="text"></el-button>
  </div>

</template>
  
  <script>
import ElImageViewer from 'element-ui/packages/image/src/image-viewer';

// import {
//   userOssSignature,
//   qnyOssSignature
// } from '@/api/creatCenter/material';
// import { storageConfigDetail } from '@/api/storageInfo/index';

// import axios from 'axios';
// import {
//   siteCategoriesInsert,
//   siteCategoriesList,
//   siteCategoriesModify,
//   siteCategoriesDetail
// } from '@/api/serviceManagement/categoriesList';
import { upload } from '@/api/saveImg/index'
import { updateDaziStatus, kickUser } from '@/api/dazi/index'
import { joinCommunityList } from '@/api/communityManagement/index'
export default {
  name: 'pictureEdit',
  components: { ElImageViewer },
  props: {
    drawerEditBoolen: {
      type: Boolean,
      default: false
    },
    // 修改回显的数据
    data: Object
  },
  data () {
    // const categoryImage = (rule, value, callback) => {
    //   console.log(this.form.img);
    //   if (!this.form.img) {
    //     callback(new Error('请上传图片'));
    //   } else {
    //     callback();
    //   }
    // };
    const DEFAULT_FORM = {
      // 等级名称
      name: '',
      //   描述
      desc: '',
      // 0 普通会员  1 vip会员
      level: '1',
      //  价格
      price: '',
      // 有效期
      effective_time: '',
      // 搭子数量
      dazi_number: '',
      // 圈子数量
      circle_number: '',
      // 服务数量
      service_number: '',
      // 社群数量
      community_number: ''


    };
    return {
      radio: 2,
      storageMode: 2,
      options: [],
      imageUrl: '',
      imgViewArr: [],
      viewerVisible: false,
      // 表单数据
      form: { ...DEFAULT_FORM },
      dialogImageUrl: '',
      fileList: [],
      dialogVisible: false,
      columns: [

        // {
        //   prop: 'id',
        //   label: '排序',
        //   sortable: 'custom',
        //   showOverflowTooltip: true,
        //   minWidth: 30,
        //   align: 'center',
        //   slot: 'sort'
        // },

        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,

        },
        {
          prop: 'name',
          label: '社群名字',
          sortable: 'custom',
          width: 105,
          align: 'center',
          showOverflowTooltip: true,
          slot: 'name'

        },
        {
          prop: 'desc',
          label: '社群副标题',
          sortable: 'custom',
          width: 105,
          align: 'center',
          showOverflowTooltip: true,



        },


        {
          prop: 'allow_join_number',
          label: '允许加入人数',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          width: 205,
        },
        {
          prop: 'join_number',
          label: '已加入人数',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          width: 205,
        },
        {
          prop: 'nickname',
          label: '社群创建者',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          width: 105,
          slot: 'nickname'
        },
        {
          prop: 'join_nickname',
          label: '加入的用户',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          width: 105,
          slot: 'join_nickname'
        },

        {
          prop: 'price',
          label: '价格',
          align: 'center',
          sortable: 'custom',

          showOverflowTooltip: true,

        },




        {
          prop: 'create_time',
          label: '创建时间',
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: true,
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },

      ],
      // 表单验证规则
      rules: {
        name: [
          {
            required: true,
            message: '请输入分类名称',
            trigger: 'blur'
          }
        ],


        desc: [
          {
            required: true,
            message: '请输入描述',
            trigger: 'blur'
          }
        ],
        price: [
          {
            required: true,
            message: '请输入价格',
            trigger: 'blur'
          }
        ],
        effective_time: [
          {
            required: true,
            message: '请输入有效时间',
            trigger: 'blur'
          }
        ],
        dazi_number: [
          {
            required: true,
            message: '请输入搭子数量',
            trigger: 'blur'
          }
        ],
        circle_number: [
          {
            required: true,
            message: '请输入圈子数量',
            trigger: 'blur'
          }
        ],
        service_number: [
          {
            required: true,
            message: '请输入服务数量',
            trigger: 'blur'
          }
        ],
        community_number: [
          {
            required: true,
            message: '请输入社群数量',
            trigger: 'blur'
          }
        ],
        // // 站点 图片上传
        // img: [
        //   { required: true, validator: categoryImage, trigger: 'change' }
        // ]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      showChoose: false,
      orderInfoData: null,
      showTextarea: false,
      textarea: '',
      remark: '',
      status: 2
    };
  },
  activated () {

  },
  computed: {
    orderStatusFn: function () {
      return function (status) {

        let orderStatus = '';
        // status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
        orderStatus =
          status == 0 ? '全部' : status == 1 ? '已加入' : status == 2 ? '用户被踢出活动' : status == 3 ? '用户自己退出活动' : status == 4 ? '过期解散' : "完成";

        return orderStatus;
      };
    },

  },
  methods: {
    open (id) {
      this.$confirm('此操作将会踢出参与人员, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {

        const res = await kickUser({
          id: id
        });
        console.log(res)

        this.$message({
          type: 'success',
          message: '踢人成功'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消踢人'
        });
      });
    },
    async handleCommand (command) {
      this.open(command)



      //   this.$message('click on item ' + command);
    },
    inputChange (e) {
      console.log(e)
      if (e == 7) {
        this.showTextarea = true
        this.status = e

      } else {

        this.showTextarea = false
        this.status = e
        this.remark = null


      }
    },
    // 关闭抽屉
    handleClose () {
      console.log('查看详情');
      this.$emit('update:drawerEditBoolen', false);
    },
    // 获取存储配置
    // async storageConfig () {
    //   const res = await storageConfigDetail();

    //   // console.log(res.storageMode);

    //   this.storageMode = res?.storageMode;
    // },
    // 关闭查看器
    closeViewer () {
      this.viewerVisible = false;
    },
    // 下载图片
    handleDownload (file) {
      window.open(file.url);
    },
    // 删除图片
    handleRemove () {
      this.fileList = [];
      this.imageUrl = '';
      this.form.img = this.imageUrl;
    },
    //  图片上传个数超过限制
    exceedFn () {
      this.$message({
        message: '图片上传已达到上限,请删除后再上传',
        type: 'warning'
      });
    },
    handlePictureCardPreview () {
      const imgStr = this.imageUrl;
      console.log(imgStr);
      if (imgStr.length) {
        if (imgStr.includes(',')) {
          console.log('字符串中包含逗号');
          // 包含的进行slice(',') 分割

          this.imgViewArr = imgStr.split(',').map((item) => item.trim());
        } else {
          console.log('字符串中不包含逗号');
          this.imgViewArr = imgStr.split();
        }

        this.viewerVisible = true;
      } else {
        this.$message({
          message: '没有上传图片无法进行预览',
          type: 'warning'
        });
      }
    },

    async handleFileChange (file) {

      this.aliFn(file)
    },
    // 阿里云
    async aliFn (file) {
      this.loading = true;

      let files = file.raw;

      console.log(files)
      // 构建请求参数
      let params = new FormData();
      console.log(params);

      //   params.append('signature', '132321313');
      params.append('file', files);
      console.log(params);

      //   let config = {
      //     headers: {
      //       'Access-Control-Allow-Origin': '*',
      //       'x-oss-callback-Authorization': getToken()
      //     }
      //   };

      const res = await upload(params);
      //   let result = await axios.post(res.host, param, config);
      //   let url = res.host + '/' + date + suffix;
      console.log(res);
      if (res.code == 0) {
        this.form.img = res.data.url
        this.loading = false;
      }
      //   this.form.categoryImages = url;
      //   this.imageUrl = url;
      //   this.loading = false;
    },

    /* 保存编辑 */
    save () {
      // 判断如果下架之前需要判断当前是否还有参与人员
      const join_data = this.orderInfoData.join_data.filter(item => item.status == 1);
      console.log(join_data)
      if (join_data.length) {
        this.$message({
          message: '当前搭子还有参加人员请踢掉所有人方可下架',
          type: 'warning'
        });


      } else {
        this.loading = true;

        const saveOrUpdate = updateDaziStatus
        saveOrUpdate({
          status: this.status,
          id: this.orderInfoData.id,
          remark: this.remark
        })
          .then((msg) => {
            console.log(msg);
            this.loading = false;
            this.$message.success(msg.message);

            this.handleClose();
            this.$emit('done');
          })
          .catch((e) => {
            this.loading = false;
            this.$message.error(e.message);
          });
      }


    },
    datasource ({ page, limit, where }) {
      return joinCommunityList({
        page,
        limit,
        ...where,

      });
    },
    /* 刷新表格 */
    reload (where) {
      console.log(where)
      this.$refs.table.reload({ page: 1, where: where });
    },
    /* 更新visible */
  },
  watch: {
    drawerEditBoolen (visible) {
      this.$nextTick(async () => {
        if (visible) {
          console.log(this.data);
          if (this.data) {
            this.reload({ id: this.data.id })


            this.isUpdate = true;
          } else {
            this.isUpdate = false;
          }
        }
      });
    }
  }
};
  </script>
  
  <style lang="less" scoped>
/*隐藏input（type=number)右边的小箭头*/
/deep/.delInput input::-webkit-outer-spin-button,
/deep/.delInput input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/.delInput input[type='number'] {
  -moz-appearance: textfield;
}
/deep/.el-textarea__inner {
  margin-top: 20px;
  min-height: 150px !important;
}
.img {
  width: 42px;
  height: 42px;
}

.threePoints {
  width: 16px;
  height: 16px;
}
.foodsDiv div {
  margin-left: 20px;
  margin-top: 10px;
}
.height83 {
  height: 83vh;
}
.hLabel {
  margin: 10px 0 20px;
  font-weight: 700;
  &::before {
    content: '';
    display: inline-block;
    vertical-align: top;

    margin-right: 5px;
    height: 23px;
    width: 6px;
    background-color: #1e6ceb;
  }
}
.drawer__footer {
  display: flex;
  justify-content: flex-start;
  margin-left: 15px;
}
</style>
  